package com.app.shop.config;

import com.app.shop.service.shop.WgPictureService;
import com.app.shop.service.system.DictService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * StartupListener 系统启动监听
 *
 * @author chenliwei
 * @Date: create in 16:17 2018-3-28
 */
@Component
@PropertySource(value = "classpath:application.properties",encoding = "utf-8")
public class StartupListener implements ApplicationListener<ContextRefreshedEvent> {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private DictService dictService;

    @Autowired
    private WgPictureService wgPictureService;
    /**
     * 初始化标识防止重复初始化
     */
    private static boolean init = true;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if (init) {
            //初始化字典
            dictService.initSysDict();
            //将图片载入内存
            wgPictureService.initWgPictureAllList();
            init=false;
        }
    }
}
